home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 2 / CU Amiga Magazine's Super CD-ROM 02 (1996)(EMAP Images)(GB)[!][issue 1996-04].iso / magazine / amiga_e / epp / pmodules / stack.e < prev    next >
Text File  |  1980-01-05  |  911b  |  43 lines

  1. OPT TURBO
  2.  
  3. OBJECT st_stackType
  4.   top, count
  5. ENDOBJECT
  6.  
  7. OBJECT st_stackNodeType
  8.   pred, data
  9. ENDOBJECT
  10.  
  11. PROC st_init(theStack:PTR TO st_stackType)
  12. /* Simply declare the stack variable as st_stackType.   The status */
  13. /* of the stack can be checked by testing stackname.count.         */
  14.   theStack.top:=NIL
  15.   theStack.count:=0
  16. ENDPROC
  17.   /* st_init */
  18.  
  19.  
  20. PROC st_push(theStack:PTR TO st_stackType, addr)
  21.   DEF newNode:PTR TO st_stackNodeType
  22.   IF (newNode:=New(SIZEOF st_stackNodeType))=NIL THEN Raise("MEM")
  23.   newNode.data:=addr
  24.   newNode.pred:=theStack.top
  25.   theStack.top:=newNode
  26.   theStack.count:=theStack.count+1
  27. ENDPROC
  28.   /* st_push */
  29.  
  30.  
  31. PROC st_pop(theStack:PTR TO st_stackType)
  32.   DEF node:PTR TO st_stackNodeType, addr=NIL
  33.   IF theStack.count
  34.     node:=theStack.top
  35.     addr:=node.data
  36.     theStack.top:=node.pred
  37.     Dispose(node)
  38.     theStack.count:=theStack.count-1
  39.   ENDIF
  40. ENDPROC addr
  41.   /* st_pop */
  42.  
  43.